package com.yunduo.world.factory;

import com.yunduo.world.constant.NetWorkConstant;
import com.yunduo.world.constant.NetWorkOperationConst;
import com.yunduo.world.constant.NetWorkRoomConstant;
import com.yunduo.world.entity.EntityInfo;
import com.yunduo.world.worker.LoginWorker;
import com.yunduo.world.worker.OperationWorker;
import com.yunduo.world.worker.RoomWorker;
import com.yunduo.world.worker.ThrowWorker;
import io.netty.channel.ChannelHandlerContext;

/**
 * 生产处理各种数据的worker
 *  默认使用异常数据处理Worker
 */
public class WorldFactory {
    public static ChannelWorker createChannelWorker(ChannelHandlerContext ctx, EntityInfo.Entity msg) {
        ChannelWorker channelWorker = new ThrowWorker();
        String operation = msg.getOperation();
        if (NetWorkConstant.LOGIN.equals(operation)){
            channelWorker = new LoginWorker();
        }
        if (NetWorkRoomConstant.ROOM.equals(operation)){
            channelWorker = new RoomWorker();
        }
        if (NetWorkOperationConst.OPERATION.equals(operation)){
            channelWorker = new OperationWorker();
        }
        channelWorker.config(ctx,msg);
        return channelWorker;
    }
}
